# ========================================== # Change Outlook to Online Mode for All Users # ========================================== param( [string[]]$ExcludedUsers ) $OfficeVersions = @("16.0","15.0","14.0") # Get all user SIDs except system accounts $ExcludedSIDs = @( "S-1-5-18", # SYSTEM "S-1-5-19", # LOCAL SERVICE "S-1-5-20" # NETWORK SERVICE #"S-1-5-80-*" # All service accounts (NT SERVICE\*) ) foreach ($user in $ExcludedUsers) { try { $sid = (New-Object System.Security.Principal.NTAccount($user)). Translate([System.Security.Principal.SecurityIdentifier]). Value Write-Host "[INFO] Excluding User: $user" Write-Host "[INFO] SID: $sid" $ExcludedSIDs += $sid } catch { Write-Host "[WARNING] Failed to get SID for user: $user" } } $subKeys = Get-ChildItem "Registry::HKEY_USERS" | Where-Object { $_.Name -notmatch "_Classes$" -and $_.PSChildName -notin $ExcludedSIDs -and $_.PSChildName -notmatch "^S-1-5-80-" } # Close Outlook Write-Host "Closing Outlook..." Get-Process OUTLOOK -ErrorAction SilentlyContinue | ForEach-Object { $_.CloseMainWindow() | Out-Null if (!$_.WaitForExit(10000)) { Write-Host "Force closing Outlook..." $_ | Stop-Process -Force } } Start-Sleep -Seconds 2 foreach ($sid in $subKeys) { Write-Host "" Write-Host "Processing SID: $($sid.PSChildName)" $RegPath = $null foreach ($version in $OfficeVersions) { $BasePath = "Registry::HKEY_USERS\$($sid.PSChildName)\Software\Microsoft\Office\$version\Outlook\Profiles" if (Test-Path $BasePath) { Write-Host "Detected Outlook Version: $version" $RegPath = Get-ChildItem -Path $BasePath -Recurse | Where-Object { try { (Get-ItemProperty $_.PSPath -ErrorAction Stop)."00036601" -ne $null } catch { $false } } | Select-Object -First 1 -ExpandProperty PSPath if ($RegPath) { break } } } if (-not $RegPath) { Write-Host "No Outlook profile found for SID: $($sid.PSChildName)" continue } Write-Host "Detected Registry Path:" Write-Host $RegPath Write-Host "Changing Outlook to Online Mode..." try { $currentValue = (Get-ItemProperty -Path $RegPath -ErrorAction SilentlyContinue)."00036601" # 0x04 = Cached Exchange Mode enabled if ($currentValue -and ($currentValue[0] -eq 4)) { # Set Online Mode Set-ItemProperty ` -Path $RegPath ` -Name "00036601" ` -Value ([byte[]](0,0,0,0)) ` -Type Binary Write-Host "[SUCCESS] Registry updated for SID: $($sid.PSChildName)" } else { Write-Host "[INFO] Already in Online Mode or unknown state. Skipping." } } catch { Write-Host "[ERROR] Failed to update registry for SID: $($sid.PSChildName)" Write-Host $_.Exception.Message } # Verify value $value = (Get-ItemProperty -Path $RegPath)."00036601" Write-Host "Current Registry Value:" ($value -join " ") } Start-Sleep -Seconds 2 # Restart Outlook Write-Host "`n[INFO] Restarting Outlook..." try { Start-Process "outlook.exe" Write-Host "[SUCCESS] Outlook restarted." } catch { Write-Host "[WARNING] Could not automatically start Outlook." Write-Host $_.Exception.Message } Write-Host "Done."